<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
</head>
<body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.js"></script>
<script>
    // 添加请求拦截器 先添加后执行
    axios.interceptors.request.use(
        config=>{
            console.log('request interceptors1 onresolved1')
            return config
        },
        error=>{
            console.log('request interceptors1 onrejected1 error')
            return Promise.reject(error)
        }
    )
    axios.interceptors.request.use(
        config=>{
            console.log('request interceptors2 onresolved2')
            return config
        },
        error=>{
            console.log('request interceptors2 onrejected2 error')
            return Promise.reject(error)
        }
    )
    // 响应拦截器 后添加后执行
    axios.interceptors.response.use(
        response=>{
            console.log('response interceptors1 onresolved1')
            return response
        },
        error=>{
            console.log('response interceptors1 onrejected1 error')
            return Promise.reject(error)
        }
    )
    axios.interceptors.response.use(
        response=>{
            console.log('response interceptors2 onresolved2')
            return response
        },
        error=>{
            console.log('response interceptors2 onrejected2 error')
            return Promise.reject(error)
        }
    )

    axios.get('http://localhost:3000/posts')
        .then(response=>{
            console.log('data',response.data)
        })
        .catch(error=>{
            console.log('error',error.message)
        })
</script>
</body>
</html>
